home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / mordor_2.000 / mordor_2 / src / command8.c < prev    next >
C/C++ Source or Header  |  1995-04-20  |  23KB  |  893 lines

  1. /*
  2.  * COMMAND8.C:
  3.  *
  4.  *    Additional user routines.
  5.  *
  6.  *    Copyright (C) 1991, 1992, 1993 Brett J. Vickers
  7.  *
  8.  */
  9.  
  10. #include "mstruct.h"
  11. #include "mextern.h"
  12. #include <sys/time.h>
  13.  
  14. /**********************************************************************/
  15. /*                give                      */
  16. /**********************************************************************/
  17.  
  18. /* This function allows a player to give an item in his inventory to */
  19. /* another player or monster.                         */
  20.  
  21. int give(ply_ptr, cmnd)
  22. creature    *ply_ptr;
  23. cmd        *cmnd;
  24. {
  25.     object        *obj_ptr;
  26.     creature    *crt_ptr;
  27.     room        *rom_ptr;
  28.     int        fd;
  29.  
  30.     fd = ply_ptr->fd;
  31.     rom_ptr = ply_ptr->parent_rom;
  32.  
  33.     if(cmnd->num < 3) {
  34.         print(fd, "Give what to whom?\n");
  35.         return(0);
  36.     }
  37.  
  38.     if(cmnd->str[1][0] == '$') {
  39.         give_money(ply_ptr, cmnd);
  40.         return(0);
  41.     }
  42.  
  43.     obj_ptr = find_obj(ply_ptr, ply_ptr->first_obj,
  44.                cmnd->str[1], cmnd->val[1]);
  45.  
  46.     if(!obj_ptr) {
  47.         print(fd, "You don't have that.\n");
  48.         return(0);
  49.     }
  50.  
  51.     F_CLR(ply_ptr, PHIDDN);
  52.  
  53.     cmnd->str[2][0] = up(cmnd->str[2][0]);
  54.     crt_ptr = find_crt(ply_ptr, rom_ptr->first_ply,
  55.                cmnd->str[2], cmnd->val[2]);
  56.  
  57.     if(!crt_ptr) {
  58.         cmnd->str[2][0] = low(cmnd->str[2][0]);
  59.         crt_ptr = find_crt(ply_ptr, rom_ptr->first_mon,
  60.                    cmnd->str[2], cmnd->val[2]);
  61.         if(!crt_ptr) {
  62.             print(fd, "I don't see that person here.\n");
  63.             return(0);
  64.         }
  65.     }
  66.  
  67.     if(crt_ptr == ply_ptr) {
  68.         print(fd, "You can't give something to yourself.\n");
  69.         return(0);
  70.     }
  71.  
  72.     if(obj_ptr->questnum) {
  73.         print(fd, "You can't give away a quest object.\n");
  74.         return(0);
  75.     }
  76.  
  77.     if(crt_ptr->type == PLAYER && (weight_ply(crt_ptr) + 
  78.        weight_obj(obj_ptr) > max_weight(crt_ptr))) {
  79.         print(fd, "%s can't hold anymore.\n", crt_ptr->name);
  80.         return(0);
  81.     }
  82.  
  83.     del_obj_crt(obj_ptr, ply_ptr);
  84.     add_obj_crt(obj_ptr, crt_ptr);
  85.  
  86.     print(fd, "You give %1i to %m.\n", obj_ptr, crt_ptr);
  87.     print(crt_ptr->fd, "%M gave %1i to you.\n", ply_ptr, obj_ptr);
  88.     broadcast_rom2(fd, crt_ptr->fd, ply_ptr->rom_num, "%M gave %1i to %m.",
  89.                ply_ptr, obj_ptr, crt_ptr);
  90.  
  91.     return(0);
  92.  
  93. }
  94.  
  95. /**********************************************************************/
  96. /*                give_money                  */
  97. /**********************************************************************/
  98.  
  99. /* This function allows a player to give gold to another player.  Gold */
  100. /* is interpreted as gold if it is preceded by a dollar sign.           */
  101.  
  102. void give_money(ply_ptr, cmnd)
  103. creature    *ply_ptr;
  104. cmd        *cmnd;
  105. {
  106.     creature    *crt_ptr;
  107.     room        *rom_ptr;
  108.     long        amt;
  109.     int        fd;
  110.  
  111.     rom_ptr = ply_ptr->parent_rom;
  112.     fd = ply_ptr->fd;
  113.  
  114.     amt = atol(&cmnd->str[1][1]);
  115.     if(amt < 1) {
  116.         print(fd, "Get real.\n");
  117.         return;
  118.     }
  119.     if(amt > ply_ptr->gold) {
  120.         print(fd, "You don't have that much gold.\n");
  121.         return;
  122.     }
  123.  
  124.     cmnd->str[2][0] = up(cmnd->str[2][0]);
  125.     crt_ptr = find_crt(ply_ptr, rom_ptr->first_ply,
  126.                cmnd->str[2], cmnd->val[2]);
  127.  
  128.     if(!crt_ptr || crt_ptr == ply_ptr) {
  129.         cmnd->str[2][0] = low(cmnd->str[2][0]);
  130.         crt_ptr = find_crt(ply_ptr, rom_ptr->first_mon,
  131.               cmnd->str[2], cmnd->val[2]);
  132.  
  133.         if(!crt_ptr) {
  134.             print(fd, "That person is not here.\n");
  135.             return;
  136.         }
  137.     }
  138.  
  139.     crt_ptr->gold += amt;
  140.     ply_ptr->gold -= amt;
  141.  
  142.     print(fd, "Ok.\n");
  143.     
  144.     print(crt_ptr->fd, "%M gave you %ld gold pieces.\n", 
  145.           ply_ptr, amt);
  146.     broadcast_rom2(fd, crt_ptr->fd, ply_ptr->rom_num, 
  147.                "%M gave %m %ld gold pieces.", ply_ptr, crt_ptr, amt);
  148.  
  149. }
  150.  
  151. /**********************************************************************/
  152. /*                repair                      */
  153. /**********************************************************************/
  154.  
  155. /* This function allows a player to repair a weapon or armor if he is */
  156. /* in a repair shoppe.  There is a chance of breakage.              */
  157.  
  158. int repair(ply_ptr, cmnd)
  159. creature    *ply_ptr;
  160. cmd        *cmnd;
  161. {
  162.     object    *obj_ptr;
  163.     room    *rom_ptr;
  164.     long    cost;
  165.     int    fd, broke;
  166.  
  167.     fd = ply_ptr->fd;
  168.     rom_ptr = ply_ptr->parent_rom;
  169.  
  170.     if(cmnd->num < 2) {
  171.         print(fd, "Repair what?\n");
  172.         return(0);
  173.     }
  174.  
  175.     if(!F_ISSET(rom_ptr, RREPAI)) {
  176.         print(fd, "This is not a repair shop.\n");
  177.         return(0);
  178.     }
  179.  
  180.     obj_ptr = find_obj(ply_ptr, ply_ptr->first_obj,
  181.                cmnd->str[1], cmnd->val[1]);
  182.  
  183.     if(!obj_ptr) {
  184.         print(fd, "You don't have that.\n");
  185.         return(0);
  186.     }
  187.  
  188.     F_CLR(ply_ptr, PHIDDN);
  189.  
  190.     if(F_ISSET(obj_ptr, ONOFIX)) {
  191.         print(fd, "The smithy cannot repair that.\n");
  192.         return(0);
  193.     }
  194.  
  195.     if(obj_ptr->type > MISSILE && obj_ptr->type != ARMOR) {
  196.         print(fd, "You can only repair weapons and armor.\n");
  197.         return(0);
  198.     }
  199.  
  200.     if(obj_ptr->shotscur > MAX(3, obj_ptr->shotsmax/10)) {
  201.         print(fd, "It's not broken yet.\n");
  202.         return(0);
  203.     }
  204.  
  205.     cost = obj_ptr->value / 2;
  206.  
  207.     if(ply_ptr->gold < cost) {
  208.         print(fd, "You don't have enough money.\n");
  209.         return(0);
  210.     }
  211.  
  212.     print(fd, "The smithy takes %ld gold pieces from you.\n", cost);
  213.     ply_ptr->gold -= cost;
  214.  
  215.     broadcast_rom(fd, ply_ptr->rom_num, "%M has the smithy repair %1i.",
  216.               ply_ptr, obj_ptr);
  217.  
  218.     broke = mrand(1,100) + bonus[ply_ptr->piety];
  219.     if((broke <= 15 && obj_ptr->shotscur < 1) ||
  220.        (broke <= 5 && obj_ptr->shotscur > 0)) {
  221.         print(fd, "\"Darnitall!\" shouts the smithy, \"I broke another. Sorry %s.\"\n", F_ISSET(ply_ptr, PMALES) ? "lad":"lass");
  222.         broadcast_rom(fd, ply_ptr->rom_num, "Oops!  He broke it.");
  223.         if(obj_ptr->shotscur > 0) {
  224.             print(fd, "He gives your money back.\n");
  225.             ply_ptr->gold += cost;
  226.         }
  227.         del_obj_crt(obj_ptr, ply_ptr);
  228.         free_obj(obj_ptr);
  229.         return(0);
  230.     }
  231.  
  232.     if((F_ISSET(obj_ptr, OENCHA) || obj_ptr->adjustment) &&
  233.         mrand(1,50) > ply_ptr->piety) {
  234.         print(fd, "\"It lost that nice glow,\" says the smithy.\n");
  235.         if(obj_ptr->type == ARMOR && obj_ptr->wearflag == BODY)
  236.             obj_ptr->armor =
  237.                 MAX(obj_ptr->armor - obj_ptr->adjustment*2, 0);
  238.         else if(obj_ptr->type == ARMOR)
  239.             obj_ptr->armor =
  240.                 MAX(obj_ptr->armor - obj_ptr->adjustment, 0);
  241.         else if(obj_ptr->type <= MISSILE) {
  242.             obj_ptr->shotsmax -= obj_ptr->adjustment*10;
  243.             obj_ptr->pdice =
  244.                 MAX(obj_ptr->pdice - obj_ptr->adjustment, 0);
  245.         }
  246.         obj_ptr->adjustment = 0;
  247.         F_CLR(obj_ptr, OENCHA);
  248.     }
  249.  
  250.     obj_ptr->shotscur = (obj_ptr->shotsmax * mrand(5,9)) / 10;
  251.  
  252.     print(fd, "The smithy hands %i back to you, almost good as new.\n", 
  253.         obj_ptr);
  254.  
  255.     return(0);
  256.  
  257. }
  258.  
  259. /**********************************************************************/
  260. /*                prt_time                  */
  261. /**********************************************************************/
  262.  
  263. /* This function outputs the time of day (realtime) to the player.    */
  264.  
  265. int prt_time(ply_ptr)
  266. creature    *ply_ptr;
  267. {
  268.     char    *str;
  269.     long    t;
  270.     int    fd, daytime;
  271.  
  272.     fd = ply_ptr->fd;
  273.  
  274.     daytime = (int)(Time % 24L);
  275.     print(fd, "Game-Time: %d o'clock %s.\n", daytime%12 == 0 ? 12 :
  276.           daytime%12, daytime > 11 ? "PM":"AM");
  277.  
  278.     t = time(0);
  279.     str = ctime(&t);
  280.     str[strlen(str)-1] = 0;
  281.     
  282.     print(fd, "Real-Time: %s (PST).\n", str);
  283.  
  284.     return(0);
  285.  
  286. }
  287.  
  288. /**********************************************************************/
  289. /*                circle                      */
  290. /**********************************************************************/
  291.  
  292. /* This function allows fighters and barbarians to run circles about an */
  293. /* enemy, confusing it for several seconds.                */
  294.  
  295. int circle(ply_ptr, cmnd)
  296. creature    *ply_ptr;
  297. cmd        *cmnd;
  298. {
  299.     creature    *crt_ptr;
  300.     room        *rom_ptr;
  301.     long        i, t;
  302.     int        chance, delay, fd;
  303.  
  304.     fd = ply_ptr->fd;
  305.     rom_ptr = ply_ptr->parent_rom;
  306.  
  307.     if(cmnd->num < 2) {
  308.         print(fd, "Circle whom?\n");
  309.         return(0);
  310.     }
  311.  
  312.     if(ply_ptr->class != FIGHTER && ply_ptr->class != BARBARIAN &&
  313.        ply_ptr->class < CARETAKER) {
  314.         print(fd, "Only barbarians and fighters may circle.\n");
  315.         return(0);
  316.     }
  317.  
  318.     crt_ptr = find_crt(ply_ptr, rom_ptr->first_mon,
  319.                cmnd->str[1], cmnd->val[1]);
  320.  
  321.     if(!crt_ptr) {
  322.         cmnd->str[1][0] = up(cmnd->str[1][0]);
  323.         crt_ptr = find_crt(ply_ptr, rom_ptr->first_ply,
  324.                    cmnd->str[1], cmnd->val[1]);
  325.  
  326.         if(!crt_ptr || crt_ptr == ply_ptr || strlen(cmnd->str[1]) < 3) {
  327.             print(fd, "That is not here.\n");
  328.             return(0);
  329.         }
  330.     }
  331.  
  332.     if(crt_ptr->type == PLAYER) {
  333.         if(F_ISSET(rom_ptr, RNOKIL)) {
  334.             print(fd, "No killing allowed in this room.\n");
  335.             return(0);
  336.         }
  337.  
  338.             if((!F_ISSET(ply_ptr,PPLDGK) || !F_ISSET(crt_ptr,PPLDGK)) ||
  339.                 (BOOL(F_ISSET(ply_ptr,PKNGDM)) == BOOL(F_ISSET(crt_ptr,PKNGDM))) ||
  340.                 (! AT_WAR)) {
  341.                 if(!F_ISSET(ply_ptr, PCHAOS)) {
  342.                     print(fd, "Sorry, you're lawful.\n");
  343.                     return (0);
  344.                 }
  345.                 if(!F_ISSET(crt_ptr, PCHAOS)) {
  346.                     print(fd, "Sorry, that player is lawful.\n");
  347.                     return (0);
  348.                 }     
  349.             }
  350.     if(is_charm_crt(ply_ptr->name, crt_ptr) && F_ISSET(crt_ptr, PCHARM)) {
  351.                 print(fd, "You are too fond of %s to do that.\n", crt_ptr->name);
  352.                 return(0);
  353.             }
  354.  
  355.     }
  356.  
  357.     i = LT(ply_ptr, LT_ATTCK);
  358.     t = time(0);
  359.  
  360.     if(i > t) {
  361.         please_wait(fd, i-t);
  362.         return(0);
  363.     }
  364.  
  365.     F_CLR(ply_ptr, PHIDDN);
  366.     if(F_ISSET(ply_ptr, PINVIS)) {
  367.         F_CLR(ply_ptr, PINVIS);
  368.         print(fd, "Your invisibility fades.\n");
  369.         broadcast_rom(fd, ply_ptr->rom_num, "%M fades into view.",
  370.                   ply_ptr);
  371.     }
  372.  
  373.     chance = 50 + (ply_ptr->level-crt_ptr->level)*10 +
  374.          (bonus[ply_ptr->dexterity] -bonus[crt_ptr->dexterity])*2;
  375.     if (crt_ptr->type == MONSTER && F_ISSET(crt_ptr, MUNDED))
  376.         chance -= (5 + crt_ptr->level*2);
  377.     chance = MIN(80, chance);
  378.     if(F_ISSET(crt_ptr, MNOCIR) || F_ISSET(ply_ptr, PBLIND))
  379.         chance=1;
  380.         
  381.     if(crt_ptr->type != PLAYER) {
  382.         if(F_ISSET(crt_ptr, MUNKIL)) {
  383.             print(fd, "You cannot harm %s.\n",
  384.                 F_ISSET(crt_ptr, MMALES) ? "him":"her");
  385.             return(0);
  386.         }
  387.         add_enm_crt(ply_ptr->name, crt_ptr);
  388.     }
  389.  
  390.     if(mrand(1,100) <= chance) {
  391.         if(ply_ptr->class == BARBARIAN)
  392.             delay = mrand(6,9);
  393.         else
  394.             delay = mrand(6,12);
  395.         crt_ptr->lasttime[LT_ATTCK].ltime = t;
  396.         crt_ptr->lasttime[LT_ATTCK].interval = delay;
  397.  
  398.         print(fd, "You circle %m.\n", crt_ptr);
  399.  
  400.         print(crt_ptr->fd, "%M circles you.\n", ply_ptr);
  401.         broadcast_rom2(fd, crt_ptr->fd, ply_ptr->rom_num, 
  402.                    "%M circles %m.", ply_ptr, crt_ptr);
  403.         ply_ptr->lasttime[LT_ATTCK].interval = 2;
  404.     }
  405.     else {
  406.         print(fd, "You failed to circle it.\n");
  407.         print(crt_ptr->fd, "%M tried to circle you.\n", ply_ptr);
  408.         broadcast_rom2(fd, crt_ptr->fd, ply_ptr->rom_num,
  409.                    "%M tried to circle %m.", ply_ptr, crt_ptr);
  410.         ply_ptr->lasttime[LT_ATTCK].interval = 3;
  411.     }
  412.  
  413.     ply_ptr->lasttime[LT_ATTCK].ltime = t;
  414.  
  415.     return(0);
  416.  
  417. }
  418.  
  419. /**********************************************************************/
  420. /*                bash                      */
  421. /**********************************************************************/
  422.  
  423. /* This function allows fighters and barbarians to "bash" an opponent, */
  424. /* doing less damage than a normal attack, but knocking the opponent   */
  425. /* over for a few seconds, leaving him unable to attack back.           */
  426.  
  427. int bash(ply_ptr, cmnd)
  428. creature    *ply_ptr;
  429. cmd        *cmnd;
  430. {
  431.     creature    *crt_ptr;
  432.     room        *rom_ptr;
  433.     long        i, t;
  434.     int        m, n, chance, fd, p, addprof;
  435.  
  436.     fd = ply_ptr->fd;
  437.     rom_ptr = ply_ptr->parent_rom;
  438.  
  439.     if(cmnd->num < 2) {
  440.         print(fd, "Bash whom?\n");
  441.         return(0);
  442.     }
  443.  
  444.     if(ply_ptr->class != FIGHTER && ply_ptr->class != BARBARIAN &&
  445.        ply_ptr->class < CARETAKER) {
  446.         print(fd, "Only barbarians and fighters may bash.\n");
  447.         return(0);
  448.     }
  449.  
  450.     crt_ptr = find_crt(ply_ptr, rom_ptr->first_mon,
  451.                cmnd->str[1], cmnd->val[1]);
  452.  
  453.     if(!crt_ptr) {
  454.         cmnd->str[1][0] = up(cmnd->str[1][0]);
  455.         crt_ptr = find_crt(ply_ptr, rom_ptr->first_ply,
  456.                    cmnd->str[1], cmnd->val[1]);
  457.  
  458.         if(!crt_ptr || crt_ptr == ply_ptr || strlen(cmnd->str[1])<3) {
  459.             print(fd, "That isn't here.\n");
  460.             return(0);
  461.         }
  462.  
  463.     }
  464.  
  465.     if(crt_ptr->type != PLAYER && is_enm_crt(ply_ptr->name, crt_ptr)) {
  466.         print(fd, "Not while you're already fighting %s.\n",
  467.               F_ISSET(crt_ptr, MMALES) ? "him":"her");
  468.         return(0);
  469.     }
  470.     else if(crt_ptr->type == PLAYER) {
  471.         if(F_ISSET(rom_ptr, RNOKIL)) {
  472.             print(fd, "No killing allowed in this room.\n");
  473.             return(0);
  474.         }
  475.  
  476.             if((!F_ISSET(ply_ptr,PPLDGK) || !F_ISSET(crt_ptr,PPLDGK)) ||
  477.                 (BOOL(F_ISSET(ply_ptr,PKNGDM)) == BOOL(F_ISSET(crt_ptr,PKNGDM))) ||
  478.                 (! AT_WAR)) {
  479.                 if(!F_ISSET(ply_ptr, PCHAOS)) {
  480.                     print(fd, "Sorry, you're lawful.\n");
  481.                     return (0);
  482.                 }
  483.                 if(!F_ISSET(crt_ptr, PCHAOS)) {
  484.                     print(fd, "Sorry, that player is lawful.\n");
  485.                     return (0);
  486.                 }     
  487.             }
  488.     if(is_charm_crt(ply_ptr->name, crt_ptr)&& F_ISSET(crt_ptr, PCHARM)) {
  489.                 print(fd, "You like %s too much to do that.\n", crt_ptr->name);
  490.                 return(0);
  491.             }
  492.  
  493.     }
  494.  
  495.     i = LT(ply_ptr, LT_ATTCK);
  496.     t = time(0);
  497.  
  498.     if(i > t) {
  499.         please_wait(fd, i-t);
  500.         return(0);
  501.     }
  502.  
  503.     ply_ptr->lasttime[LT_ATTCK].ltime = t;
  504.     ply_ptr->lasttime[LT_ATTCK].interval = 3;
  505.  
  506.     F_CLR(ply_ptr, PHIDDN);
  507.     if(F_ISSET(ply_ptr, PINVIS)) {
  508.         F_CLR(ply_ptr, PINVIS);
  509.         print(fd, "Your invisibility fades.\n");
  510.         broadcast_rom(fd, ply_ptr->rom_num, "%M fades into view.",
  511.                   ply_ptr);
  512.     }
  513.  
  514.     if(crt_ptr->type != PLAYER) {
  515.         if(F_ISSET(crt_ptr, MUNKIL)) {
  516.             print(fd, "You cannot harm %s.\n",
  517.                 F_ISSET(crt_ptr, MMALES) ? "him":"her");
  518.             return(0);
  519.         }
  520.  if(F_ISSET(crt_ptr, MMGONL)) {
  521.             print(fd, "Your weapon has no effect on %m.\n",
  522.                 crt_ptr);
  523.             return(0);
  524.         }
  525.         if(F_ISSET(crt_ptr, MENONL)) {
  526.             if(!ply_ptr->ready[WIELD-1] || 
  527.                 ply_ptr->ready[WIELD-1]->adjustment < 1) {
  528.                 print(fd, "Your weapon has no effect on %m.\n",
  529.                     crt_ptr);
  530.                 return(0);
  531.             }
  532.         }  
  533.         add_enm_crt(ply_ptr->name, crt_ptr);
  534.     }
  535.  
  536.     chance = 50 + (ply_ptr->level-crt_ptr->level)*10 +
  537.         bonus[ply_ptr->strength]*3 +
  538.          (bonus[ply_ptr->dexterity] -bonus[crt_ptr->dexterity])*2;
  539.     chance += ply_ptr->class==BARBARIAN ? 5:0;
  540.     chance = MIN(85, chance);
  541.     if(F_ISSET(ply_ptr, PBLIND))
  542.         chance = MIN(20, chance);
  543.  
  544.     if(mrand(1,100) <= chance) {
  545.  
  546.         if(ply_ptr->ready[WIELD-1]) {
  547.             if(ply_ptr->ready[WIELD-1]->shotscur < 1) {
  548.                 print(fd, "Your %s is broken.\n", 
  549.                       ply_ptr->ready[WIELD-1]->name);
  550.                 add_obj_crt(ply_ptr->ready[WIELD-1], ply_ptr);
  551.                 ply_ptr->ready[WIELD-1] = 0;
  552.                 return(0);
  553.             }
  554.         }
  555.  
  556.         n = ply_ptr->thaco - crt_ptr->armor/10;
  557.         if(mrand(1,20) >= n) {
  558.  
  559.             crt_ptr->lasttime[LT_ATTCK].ltime = t;
  560.             crt_ptr->lasttime[LT_ATTCK].interval = mrand(5,8);
  561.  
  562.             if(ply_ptr->ready[WIELD-1])
  563.                 n = mdice(ply_ptr->ready[WIELD-1]) / 2;
  564.             else
  565.                 n = mdice(ply_ptr) / 2;
  566.  
  567.             if(ply_ptr->class == BARBARIAN && mrand(1,100) > 75)
  568.                 n = (n*3)/2;
  569.  
  570.             m = MIN(crt_ptr->hpcur, n);
  571.             if(crt_ptr->type != PLAYER) {
  572.                 add_enm_dmg(ply_ptr->name, crt_ptr, m);
  573.                 if(ply_ptr->ready[WIELD-1]) {
  574.                     p = MIN(ply_ptr->ready[WIELD-1]->type,
  575.                         4);
  576.                     addprof = (m * crt_ptr->experience) /
  577.                         crt_ptr->hpmax;
  578.                     addprof = MIN(addprof,
  579.                         crt_ptr->experience);
  580.                     ply_ptr->proficiency[p] += addprof;
  581.                 }
  582.             }
  583.             crt_ptr->hpcur -= n;
  584.  
  585.             print(fd, "You bash for %d damage.\n", n);
  586.             broadcast_rom2(fd, crt_ptr->fd, crt_ptr->rom_num, 
  587.                        "%M bashes %m.", ply_ptr, crt_ptr);
  588.             print(crt_ptr->fd, "%M bashed you for %d damage.\n",
  589.                   ply_ptr, n);
  590.  
  591.             ply_ptr->lasttime[LT_ATTCK].interval = 2;
  592.  
  593.             if(crt_ptr->hpcur < 1) {
  594.                 print(fd, "You killed %m.\n", crt_ptr);
  595.                 broadcast_rom2(fd, crt_ptr->fd, 
  596.                            ply_ptr->rom_num,
  597.                            "%M killed %m.", ply_ptr,
  598.                            crt_ptr);
  599.  
  600.                 die(crt_ptr, ply_ptr);
  601.             }
  602.             else
  603.                 check_for_flee(crt_ptr);
  604.         }
  605.         else {
  606.             print(fd, "Your bash failed.\n");
  607.             print(crt_ptr->fd, "%M tried to bash you.\n", ply_ptr);
  608.             broadcast_rom2(fd, crt_ptr->fd, crt_ptr->rom_num, 
  609.                        "%M tried to bash %m.", ply_ptr, 
  610.                        crt_ptr);
  611.         }
  612.     }
  613.  
  614.     else {
  615.         print(fd, "Your bash failed.\n");
  616.         print(crt_ptr->fd, "%M tried to bash you.\n", ply_ptr);
  617.         broadcast_rom2(fd, crt_ptr->fd, crt_ptr->rom_num, 
  618.                    "%M tried to bash %m.", ply_ptr, crt_ptr);
  619.     }
  620.  
  621.     return(0);
  622.  
  623. }
  624.  
  625. /**********************************************************************/
  626. /*                savegame                  */
  627. /**********************************************************************/
  628.  
  629. /* This function saves a player's game.  Since items need to be un-readied */
  630. /* before a player can be saved to a file, this function makes a duplicate */
  631. /* of the player, unreadies everything on the duplicate, and then saves    */
  632. /* the duplicate to the file.  Afterwards, the duplicate is freed from     */
  633. /* memory.                                   */
  634.  
  635. int savegame(ply_ptr, cmnd)
  636. creature    *ply_ptr;
  637. cmd        *cmnd;
  638. {
  639.     creature    *dum_ptr;
  640.     object        *obj[MAXWEAR];
  641.     int        i, n = 0;
  642.  
  643.     dum_ptr = (creature *)malloc(sizeof(creature));
  644.     if(!dum_ptr)
  645.         merror("savegame", FATAL);
  646.  
  647.     *dum_ptr = *ply_ptr;
  648.  
  649.     for(i=0; i<MAXWEAR; i++) {
  650.         if(dum_ptr->ready[i]) {
  651.             obj[n++] = dum_ptr->ready[i];
  652.             add_obj_crt(dum_ptr->ready[i], dum_ptr);
  653.             dum_ptr->ready[i] = 0;
  654.         }
  655.     }
  656.  
  657.     if(!dum_ptr->name[0]) return;
  658.  
  659.     if(save_ply(dum_ptr->name, dum_ptr) < 0)
  660.         merror("savegame", NONFATAL);
  661.  
  662.     for(i=0; i<n; i++)
  663.         del_obj_crt(obj[i], dum_ptr);
  664.  
  665.     free(dum_ptr);
  666.  
  667.     print(ply_ptr->fd, "Player saved.\n");
  668.  
  669.     return(0);
  670.  
  671. }
  672.  
  673. /**********************************************************************/
  674. /*                talk                      */
  675. /**********************************************************************/
  676.  
  677. /* This function allows players to speak with monsters if the monster */
  678. /* has a talk string set.                          */
  679.  
  680. int talk(ply_ptr, cmnd)
  681. creature    *ply_ptr;
  682. cmd        *cmnd;
  683. {
  684.     room        *rom_ptr;
  685.     creature    *crt_ptr;
  686.     ttag        *tp;
  687.     char        str[160];
  688.     int        fd;
  689.  
  690.     fd = ply_ptr->fd;
  691.     rom_ptr = ply_ptr->parent_rom;
  692.  
  693.     if(cmnd->num < 2) {
  694.         print(fd, "Talk to whom?\n");
  695.         return(0);
  696.     }
  697.  
  698.     crt_ptr = find_crt(ply_ptr, rom_ptr->first_mon,
  699.                cmnd->str[1], cmnd->val[1]);
  700.  
  701.     if(!crt_ptr) {
  702.         print(fd, "I don't see that here.\n");
  703.         return(0);
  704.     }
  705.  
  706.     F_CLR(ply_ptr, PHIDDN);
  707.  
  708.     if(cmnd->num == 2 || !F_ISSET(crt_ptr, MTALKS)) {
  709.         broadcast_rom(fd, ply_ptr->rom_num, "%M talks with %m.", 
  710.             ply_ptr, crt_ptr);
  711.  
  712.         if(crt_ptr->talk[0]) {
  713.             broadcast_rom(fd, ply_ptr->rom_num,
  714.                 "%M says to %M, \"%s\".", crt_ptr, ply_ptr,
  715.                 crt_ptr->talk);
  716.             print(fd, "%M says to you, \"%s\".\n", crt_ptr,
  717.                 crt_ptr->talk);
  718.         }
  719.         else
  720.             broadcast_rom(-1, ply_ptr->rom_num,
  721.                 "%M doesn't say anything.", crt_ptr);
  722.         if(F_ISSET(crt_ptr, MTLKAG))
  723.             add_enm_crt(ply_ptr->name, crt_ptr);
  724.     }
  725.  
  726.     else {
  727.         if(!crt_ptr->first_tlk)
  728.             if(!load_crt_tlk(crt_ptr))
  729.                 return(PROMPT);
  730.  
  731.         broadcast_rom(fd, ply_ptr->rom_num, "%M asks %m about \"%s\".",
  732.             ply_ptr, crt_ptr, cmnd->str[2]);
  733.  
  734.         tp = crt_ptr->first_tlk;
  735.         while(tp) {
  736.             if(!strcmp(cmnd->str[2], tp->key)) {
  737.                 broadcast_rom(fd, ply_ptr->rom_num,
  738.                     "%M says to %M, \"%s\".", crt_ptr,
  739.                     ply_ptr, tp->response);
  740.                 print(fd, "%M says to you, \"%s\"\n",
  741.                     crt_ptr, tp->response);
  742.                 talk_action(ply_ptr, crt_ptr, tp);
  743.                 return(0);
  744.             }
  745.             tp = tp->next_tag;
  746.         }
  747.         broadcast_rom(-1, ply_ptr->rom_num, "%M shrugs.", crt_ptr);
  748.         if(F_ISSET(crt_ptr, MTLKAG))
  749.             add_enm_crt(ply_ptr->name, crt_ptr);
  750.     }
  751.  
  752.     return(0);
  753.  
  754. }
  755.  
  756. /******************************************************************/
  757. /*                      talk_action                               */
  758. /******************************************************************/
  759. /* The talk_action function handles a monster's actin when a     *
  760.  * player asks the monster about a key word.  The format for the *
  761.  * is defined in the monster's talk file.  Currently a monster   *
  762.  * can attack, or cast spells on the player who mentions the key *
  763.  * word or preform any of the defined social commands */
  764.  
  765. void talk_action(ply_ptr, crt_ptr,tt)
  766. creature    *ply_ptr;
  767. creature    *crt_ptr;
  768. ttag        *tt;
  769. {
  770. cmd        cm;
  771. int     i, n,splno =0;
  772. object  *obj_ptr;
  773. int        (*fn)();
  774.  
  775. for (i = 0; i < COMMANDMAX;i++){
  776.     cm.str[i][0] = 0;
  777.     cm.str[i][24] = 0;
  778.     cm.val[i]    = 0;
  779. }
  780.     cm.fullstr[0] = 0;
  781.     cm.num = 0;
  782.  
  783. switch(tt->type){
  784.     case 1:     /*attack */
  785.         add_enm_crt(ply_ptr->name, crt_ptr);
  786.         broadcast_rom(ply_ptr->fd, ply_ptr->rom_num,
  787.                     "%M attacks %M\n",crt_ptr,ply_ptr);
  788.         print(ply_ptr->fd,"%M attacks you.\n",crt_ptr);
  789.         break;
  790.  
  791.     case 2:                /*action command */
  792.         if(action){
  793.             strncpy(cm.str[0],tt->action,25);
  794.             strcat(cm.fullstr,tt->action);
  795.             cm.val[0]  = 1;
  796.             cm.num = 1;
  797.  
  798.             if(tt->target)
  799.                 if(!strcmp(tt->target,"PLAYER")){
  800.                     strcpy(cm.str[1],ply_ptr->name);
  801.                     strcat(cm.fullstr," ");
  802.                     strcat(cm.fullstr,ply_ptr->name);
  803.                     cm.val[1]  = 1;
  804.                     cm.num = 2;
  805.                 }
  806.             action(crt_ptr,&cm);
  807.         }
  808.         break;
  809.     case 3:            /*cast */
  810.         if(tt->action){
  811.             n =  crt_ptr->mpcur; 
  812.             strcpy(cm.str[0],"cast");
  813.             strncpy(cm.str[1],tt->action,25);
  814.             strcpy(cm.str[2],ply_ptr->name);
  815.             cm.val[0]  = cm.val[1]  = cm.val[2]  = 1;
  816.             cm.num = 3;
  817.             sprintf(cm.fullstr,"cast %s %s",tt->action,ply_ptr->name);
  818.  
  819.             i = 0;
  820.             do {
  821.                    if(!strcmp(tt->action, spllist[i].splstr)) {
  822.                        splno = i;
  823.                         break;
  824.                 }
  825.                     i++;
  826.             } while(spllist[i].splno != -1);
  827.  
  828.             if(spllist[i].splno == -1)
  829.                 return;
  830.              fn = spllist[splno].splfn;
  831.             if(fn == offensive_spell) {
  832.                 for(i=0; ospell[i].splno != spllist[splno].splno; i++)
  833.                     if(ospell[i].splno == -1) return;
  834.                  (*fn)(crt_ptr, &cm, CAST, spllist[splno].splstr,
  835.             &ospell[i]);
  836.             }
  837.             else if(is_enm_crt(ply_ptr->name,crt_ptr)){
  838.                 print(ply_ptr->fd,"%M refuses to cast any spells on you.\n",
  839.                     crt_ptr);
  840.                 return;
  841.             }    
  842.             else
  843.               (*fn)(crt_ptr, &cm, CAST);
  844.             
  845.             if (spllist[i].splno  != SRESTO && crt_ptr->mpcur == n)
  846.                 print(ply_ptr->fd,
  847.             "%M appoligies that %s can not currently cast that spell on you.\n",
  848.             crt_ptr, (F_ISSET(crt_ptr,MMALES)) ? "he" : "she");
  849.         }
  850.         break;
  851.     case 4:
  852.         i = atoi(tt->action);
  853.         if (i > 0){
  854.             n=load_obj(i, &obj_ptr);
  855.             if(n > -1) {
  856.                 if(F_ISSET(obj_ptr, ORENCH))
  857.                     rand_enchant(obj_ptr);
  858.  
  859.                 if(weight_ply(ply_ptr) + weight_obj(obj_ptr) > 
  860.                    max_weight(ply_ptr)) {
  861.                    print(ply_ptr->fd, "You can't hold anymore.\n");
  862.                    break;
  863.                }    
  864.  
  865.                 if(obj_ptr->questnum && Q_ISSET(ply_ptr, obj_ptr->questnum-1)) {
  866.                     print(ply_ptr->fd, "You may not get that. %s.\n",
  867.                           "You have already fulfilled that quest");
  868.                     break;
  869.                 } 
  870.                 
  871.                  if(obj_ptr->questnum) {
  872.                         print(ply_ptr->fd, "Quest fulfilled!  Don't drop it.\n");
  873.                         Q_SET(ply_ptr, obj_ptr->questnum-1);
  874.                         ply_ptr->experience += quest_exp[obj_ptr->questnum-1];
  875.                         print(ply_ptr->fd, "%ld experience granted.\n",
  876.                             quest_exp[obj_ptr->questnum-1]);
  877.                         add_prof(ply_ptr,quest_exp[obj_ptr->questnum-1]);
  878.                         } 
  879.                 add_obj_crt(obj_ptr, ply_ptr);
  880.                 print(ply_ptr->fd,"%M gives you %i\n",crt_ptr, obj_ptr);
  881.                 broadcast_rom(ply_ptr->fd, ply_ptr->rom_num,
  882.                     "%M gives %m %i\n", crt_ptr,ply_ptr,obj_ptr);
  883.             }
  884.             else
  885.                 print(ply_ptr->fd,"%M has nothing to give you.\n",crt_ptr);
  886.         }  
  887.         break;
  888.     default:
  889.         break;
  890.     }
  891. return;
  892. }
  893.